<?php
	/*
	 * AJAX call to load the list of publicity messages.
	 * Publicity messages are stored in "publicity"
	 *
	 * Variables:
	 *   id (int) : Record ID of last already loaded message
	 *
	 * Returns: xml
	 *
	 */

	header('Content-type: text/xml');

	$clean["id"] = round($_GET["id"]);

	// Get a certain ID and higher, excluding the ID
	$smssql = mysql_query("SELECT * FROM publicity WHERE pubID>".$clean["id"]." AND pubIsCommand=\"0\" ORDER BY pubID DESC");
	echo '<root>';
	while($row = mysql_fetch_array($smssql, MYSQL_ASSOC)){
		if($row["pubLoadedAt"] == "0000-00-00 00:00:00"){
			if($row["pubShownAt"] == "0000-00-00 00:00:00"){
				$status = 0; // New
			}else{
				$status = 3; // Re-run of old message
			}
		}elseif($row["pubShownAt"] == "0000-00-00 00:00:00"){
			$status = 1; // Loaded, not shown
		}else{
			$status = 2; // Loaded and shown
		}

		echo "\n".'	<text id="'.$row["pubID"].'" status="'.$status.'" dt="'.substr($row["pubFirstdate"],5,11).'"><![CDATA['.($row["pubText"]).']]></text>';
	}

	$smssql = mysql_query("SELECT * FROM publicity WHERE pubID<=".$clean["id"]." AND pubIsCommand=\"0\""); // Old text messages, already on screen...
	while($row = mysql_fetch_array($smssql, MYSQL_ASSOC)){
		if($row["pubLoadedAt"] == "0000-00-00 00:00:00"){
			if($row["pubShownAt"] == "0000-00-00 00:00:00"){
				$status = 0; // New
			}else{
				$status = 3; // Re-run of old message
			}
		}elseif($row["pubShownAt"] == "0000-00-00 00:00:00"){
			$status = 1; // Loaded, not shown
		}else{
			$status = 2; // Loaded and shown
		}

		echo "\n".'	<status id="'.$row["pubID"].'" status="'.$status.'" />';
	}


	echo "\n".'</root>';

?>